package emulator.hardware.bits;

public class SerialBit extends SharedBit {
	private SharedBit inport;
	private boolean bus_bit;
	
	public SerialBit(SharedBit inport)
	{
		this.inport = inport;
		super.setValue(false);
		bus_bit = true;
		updateOutput();
	}
	
	/* (non-Javadoc)
	 * @see emulator.hardware.bits.SharedBit#getValue()
	 */
	@Override
	public synchronized boolean getValue() {
		return super.getValue();
	}

	/* (non-Javadoc)
	 * @see emulator.hardware.bits.SharedBit#setValue(boolean)
	 */
	@Override
	public synchronized void setValue(boolean value) {
		super.setValue(value);
		updateOutput();
	}

	/* (non-Javadoc)
	 * @see emulator.hardware.bits.SharedBit#toggle()
	 */
	@Override
	public synchronized void toggle() {
		super.toggle();
		updateOutput();
	}

	private void updateOutput() {
		inport.setValue(!super.getValue() && bus_bit);
	}

	public boolean getInBit() {
		return inport.getValue();
	}

	public void setBusBit(boolean value) {
		bus_bit = value;
		updateOutput();
	}
}
